from django.db import models
# Create your models here.
from django.contrib.auth.models import AbstractUser


class UserModel(AbstractUser):
    real_name = models.CharField(max_length=128, null=True, blank=True)
    phone = models.CharField(max_length=128, null=True, blank=True)
    avatar = models.ImageField(null=True, blank=True)

    class Meta:
        db_table = "bk_user"
        verbose_name = "用户表"


# python manage.py makemigrations
# python manage.py migrate
class AddressModel(models.Model):
    phone = models.CharField(max_length=128, null=True, blank=True)
    province = models.CharField(max_length=128, null=True, blank=True)
    city = models.CharField(max_length=128, null=True, blank=True)
    address = models.CharField(max_length=128, null=True, blank=True)
    user = models.ForeignKey(UserModel, blank=True, null=True, on_delete=models.CASCADE, related_name="addresses")

    class Meta:
        db_table = "bk_address"
        verbose_name = "地址表"



class Tag(models.Model):
    name = models.CharField(max_length=100)

    def __str__(self):
        return self.name

    class Meta:
        db_table = "bk_tag"
        verbose_name = "标签表"


class Article(models.Model):
    title = models.CharField(max_length=200)
    content = models.TextField()
    tags = models.ManyToManyField(Tag, related_name='articles')

    def __str__(self):
        return self.title

    class Meta:
        db_table = "bk_article"
        verbose_name = "用户表"

